//
// Created by zqh on 2023/11/26.
//

/**
  ******************************************************************************
  * @file    bsp_pwm.c
  * @author  XJTU ROBOMASTER Team
  * @brief   bsp pwm
  *          这个文件提供函数对pwm进行开启
  *
  @verbatim
  ==============================================================================

  @endverbatim
  ******************************************************************************
  * @attention
  *
  * Please add comments after adding or deleting functions to ensure code
  * specification.
  *
  ******************************************************************************
  */

/* Includes ------------------------------------------------------------------*/
#include "bsp_pwm.h"

/* ----------------------- Function Implements ------------------------------ */
/**
  * @brief  Start PWM
  * @retval None
  */
void PWM_Start(void)
{
    HAL_TIM_PWM_Start(&htim1, TIM_CHANNEL_1);//开启定时器2的通道2的PWM（控制开镜电机的）
}

void TIM_Set_PWM(TIM_HandleTypeDef *tim_pwmHandle, uint8_t Channel, uint16_t value)
{
    if (value > tim_pwmHandle->Instance->ARR)
        value = tim_pwmHandle->Instance->ARR;

    switch (Channel)
    {
        case TIM_CHANNEL_1:
            tim_pwmHandle->Instance->CCR1 = value;
            break;
        case TIM_CHANNEL_2:
            tim_pwmHandle->Instance->CCR2 = value;
            break;
        case TIM_CHANNEL_3:
            tim_pwmHandle->Instance->CCR3 = value;
            break;
        case TIM_CHANNEL_4:
            tim_pwmHandle->Instance->CCR4 = value;
            break;
    }
}


/************************ (C) COPYRIGHT XJTU ROBOMASTER ********END OF FILE****/
